import EventMng from "../../Script/EventMng";
import { GameEvent } from "../../Script/GameEvent";

const { ccclass, property } = cc._decorator;
@ccclass
export default class verticalItem extends cc.Component {

    @property({type:cc.Node, displayName: '选中状态'})
    checked: cc.Node = null;
    @property({type:cc.Node, displayName: '未选中状态'})
    unchecked: cc.Node = null;
    private index: number
    private remove: Function
    public show(info: any, index: number, remove: Function) {
        this.index = index
        this.remove = remove
        if(this.index == 0) {
            this.checked.active = true;
            this.unchecked.active = false;
        }else {
            this.checked.active = false;
            this.unchecked.active = true;
        }
        // this.label.string = info.message
        EventMng.on(GameEvent.ITEM_CLICK, this.onItemClick, this);
    }
    private onItemClick(data) {
        if(data == this.index) {
            this.checked.active = true;
            this.unchecked.active = false;
        }else{
            this.checked.active = false;
            this.unchecked.active = true;
        }
    }
    private onClickItem() {
        EventMng.emit(GameEvent.ITEM_CLICK, this.index);
    }
    private onRemove() {
        this.remove(this.index)
    }
    private onClick() {
        
    }
    onDestroy() {
        EventMng.off(GameEvent.ITEM_CLICK, this.onItemClick, this);
    }
}
